<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>租金代扣</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript">
        var grid = null;
        $(function () {
            $("#ligergrid1").ligerGrid({
                url: '<%=path%>/infside/infPostCollectDetail/initRentDetaiList.do',
                method : 'get',
                columns: [
                    { display: '代扣开始日期', name: 'beginDate', minWidth: 100, render:renderDate, align: 'center', enabledSort:true},
                    { display: '代扣结束日期', name: 'endDate', minWidth: 100, render:renderDate, align: 'center', enabledSort:true},
                    //{ display: '放款批次号', name: 'payBatchCode', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '用户号(卡号)', name: 'accId', minWidth: 150, align: 'center', enabledSort:true},
                    { display: '客户名称', name: 'customerName', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '证件号码', name: 'paperId', minWidth: 150, align: 'center', enabledSort:true},
                    { display: '交易总金额', name: 'tranAtdou', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '应收租金', name: 'receivableAtdou', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '逾期金额', name: 'overdueAtdou', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '滞纳金', name: 'amountdou', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '代扣卡创建日期', name: 'createCardTime', minWidth: 100, render:renderDate, align: 'center', enabledSort:true}
                ],
                pageSize:10,
                root:'rows',
                record:'total',
                hideLoadButton : true,
                width: '100%',
                height:380,
                heightDiff:-2,
                //checkbox:true,
                rownumbers:true
            });
            grid = liger.get("ligergrid1");
            $("#searchBar").ligerForm();
            $("#dateform").ligerForm();
            $("#searchBtn").click(function(event) {
                var form = new liger.get("searchBar");
                var data = form.getData();
                console.log(data);
                for (name in data){
                    grid.setParm(name,data[name]);
                };
                grid.reload();
            });
            $("#clearBtn").click(function(event) {
                clearLigerForm("searchBar");
            });
        });
        //生成代扣
        function genRentDeductions(){
            $.ligerDialog.confirm("确认生成代扣?", function (flag) {
                if(flag == false)return;
                var _dialog = $.ligerDialog.open({
                    target: $("#sendDatediv"),
                    title: '选择代扣日期',
                    width: 350,
                    height: 150,
                    isResize: true,
                    modal: true,
                    buttons: [{ text: '确定', onclick: function (i, d) {

                        var paybegindate = $("#paybegindate").val();
                        var payenddate = $("#payenddate").val();
                        if (paybegindate == '') {
                            top.$.ligerDialog.SQalert({content: "代扣日期(起)不能为空",SQ_type: "warning"});
                            return false; //验证不通过，不执行以下代码
                        }
                        if (payenddate == '') {
                            top.$.ligerDialog.SQalert({content: "代扣日期(止)不能为空",SQ_type: "warning"});
                            return false; //验证不通过，不执行以下代码
                        }
                        if(paybegindate>payenddate){
                            $.ligerDialog.SQalert({content: "代扣日期(起)不能大于代扣日期(止)" , SQ_type: "warning" });
                            return;
                        }
                        $("#paybegindate").val("");
                        $("#payenddate").val("");
                        _dialog.hide();
                        var wait_dialog;
                        $.ajax({
                            type: 'post',
                            dataType:'json',
                            data:'paybegindate='+paybegindate+'&payenddate='+payenddate,
                            url: '<%=path%>/infside/infPostCollectDetail/genRentDeductions.do',
                            beforeSend: function(){
                                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                            },
                            success:function(msg){
                                wait_dialog.close();
                                if(msg.success == 1){
                                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                                    if (parent.pageInTab) {
                                        parent.pageInTab.selectTabItem('infPostCollectMaster');
                                        parent.pageInTab.reload('infPostCollectRent');
                                        parent.pageInTab.reload('infPostCollectMaster');
                                    }
                                }else{
                                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                                }
                            }
                        });

                    }
                    }, { text: '关闭', onclick: function (i, d) {
                        $("#paybegindate").val("");
                        $("#payenddate").val("");
                        _dialog.hide();
                    }
                    }]
                });
                });
        }
        //格式化时间
        function renderDate(rowdata, index, value){
            var dateStr = "";
            if(null != value){
                var date = new Date(value);
                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
            }
            return dateStr;
        }
    </script>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
                <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户编号</div>
                    <div class="field">
                        <input name="customerCode" id="customerCode" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="customerName" id="customerName" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
                    <span class="sq-button sq-button-hasicon" onclick="genRentDeductions()"><i class="sqBtnIco_33"></i>生成代扣</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
<span>
            代扣文件生成规则：
			<br>
            1.按照时间段选择代扣日期（支付表应付日期，罚息取当天）
			<br>
			2.上午11点下午4点为邮储处理文件时间，如果要发送2次文件，需要第一次在11点前，第二次在4点前
			<br>
			3.验证代扣生成文件总数不能超过10，超过下午4点当天不能再生成文件
            <br>
			4.代扣文件根据批次号生成，文件个数跟批次号一致，明细选取代扣卡允许代扣的用户
			<br>
			代扣文件操作按钮：明细：查看文件代扣记录；发送：发送文件；删除：删除文件重新生成；获取回传：从邮储获取文件；
</span>
<div id="sendDatediv" style="display:none">
    <form id="dateform">
        <div class="fieldset1 clearFix">
            <div class="fieldBox col_33">
                <div class="label">代扣日期(起)</div>
                <div class="field">
                    <input name="paybegindate" id="paybegindate" type="text" class="ui-datepicker" value="">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">代扣日期(止)</div>
                <div class="field">
                    <input name="payenddate" id="payenddate" type="text" class="ui-datepicker" value="">
                </div>
            </div>
        </div>
    </form>
</div>
</body>
</html>
